<template>
  <div class="updatebirthday-container">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close')"
      @confirm="onCofirm"
    />
  </div>
</template>
<script>
import { editUserProfile } from '@/api/user'
import dayjs from 'dayjs'
export default {
  name: '',
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },
  methods: {
    async onCofirm () {
      // 保存提示
      this.$toast.loading({
        message: '保存中...',
        forbidClick: true,
        duration: 0
      })

      // 调用接口, 修改性别
      await editUserProfile({
        birthday: dayjs(this.currentDate).format('YYYY-MM-DD')
      })

      // 修改成功, 提示
      this.$toast.success({
        message: '保存成功',
        forbidClick: true
      })
      // 向父组件发射自定义方法, 修改父组件性别
      this.$emit('input', dayjs(this.currentDate).format('YYYY-MM-DD'))
      // 向父组件发射自定义方法, 关闭弹层
      this.$emit('close')
    }
  }
}
</script>
<style lang="less">
</style>
